package com.hdaccp.beike

import org.apache.spark.sql.SparkSession

/**
  * DataFrame入门
  */
object Demo1 {
  def main(args: Array[String]): Unit = {
      val sparkSession = SparkSession.builder()
      .master("local[2]")
      .appName("beikeDemo1App")
      .getOrCreate()

    ////对于将RDD转换为DataFrames等隐式转换，请导入
    import sparkSession.implicits._

    val dataFrame = sparkSession.read.json("f:/resources/people.json")
    //以树格式df 打印模式
    dataFrame.printSchema()

    dataFrame.show()
    println("---------------------------8")
    dataFrame.select("name").show()
    println("---------------------------")
    dataFrame.select(($"name").as("姓名"),($"age" +5).as("年龄")).show()
    println("--------------------------------")
    dataFrame.filter($"age" > 21).show()
    println("--------------------------------")
    dataFrame.groupBy("age").count().show()


    sparkSession.stop()
  }
}
